package com.shh.rabbitmq.schedule;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.shh.rabbitmq.config.RabbitTemplateConfig;
import com.shh.rabbitmq.dao.OrderMsgDao;
import com.shh.rabbitmq.domin.OrderDO;
/**
 * 定时器定时推送未发送成功的订单信息
 * @author shaoh
 *
 */

@Service
public class ScheduledService {
	
	@Autowired
	private OrderMsgDao orderMsgDao;
	
	@Autowired
	private RabbitTemplateConfig rabbitTemplateConfig;
	
	///注意cron表达式的用法；
	@Scheduled(cron = "0/3 * * * * ?")
	public void reSend(){
	      List<OrderDO> list =  orderMsgDao.getUnSendOrder();
	      for (OrderDO orderDO : list) {
	    	    System.out.println("每三秒定时重发订单消息=====》消息内容："+orderDO.toString());
	    		rabbitTemplateConfig.send(orderDO);
		  }
	}
	
	
	

}
